﻿using System.Collections.Generic;
using BSU.CSCE.Data.Model;
using BSU.CSCE.Data.Repositories;
using BSU.CSCE.Data.Repositories.Interfaces;

namespace BSU.CSCE.Services
{
    public class Administrator
    {
        #region Fields

        private IUserRepository _userRepository;
        private IPublicationRepository _publicationRepository;

        #endregion

        #region Properties

        public IUserRepository UserRepository
        {
            get
            {
                if (_userRepository == null)
                    _userRepository = new UserRepository();
                return _userRepository;
            }
            set { _userRepository = value; }
        }

        public IPublicationRepository PublicationRepository
        {
            get
            {
                if (_publicationRepository == null)
                    _publicationRepository = new PublicationRepository();
                return _publicationRepository;
            }
            set { _publicationRepository = value; }
        }

        #endregion

        #region Methods

        #region User methods

        public User GetUser(int id)
        {
            return UserRepository.Get(id);
        }

        #endregion

        #region Publication methods

        public Publication GePublication(int id)
        {
            return PublicationRepository.Get(id);
        }

        public List<Publication> ListPublishedPublications(PublicationType type, string sortPath, bool asceding, int startIndex, int count, out int totalCount)
        {
            return PublicationRepository.ListPublished(type, sortPath, asceding, startIndex, count, out totalCount);
        }

        public Publication CreatePublication(Publication publication)
        {
            //UserValidator.ValidateEntity(user);

            publication = PublicationRepository.Save(publication);

            return publication;
        }

        #endregion

        #endregion
    }
}
